// void, Obj This, Obj bld

Unit this;
Hero h;
point pt;
point ptStart;
Building building;

Sleep(rand(100)+30);

this = This.AsUnit;

if (.IsValid) // leave parry mode at new command
 .SetParryMode(false);

if (!bld.IsValid)
	return;

if(!.IsMilitary) { bld.Damage(100000); return; }
if(.IsHeirOf("ShipBattle")) { bld.Damage(100000); return; }
if(.IsHeirOf("Wagon")) { bld.Damage(100000); return; }
if(.IsHeirOf("ShipTransport")) { bld.Damage(100000); return; }
if(.IsHeirOf("Catapult")) { bld.Damage(100000); return; }
if(.IsHeirOf("Animal")) { bld.Damage(100000); return; }
if(.IsHeirOf("Hero")) { bld.Damage(100000); return; }
if(.IsHeirOf("Sentry")) { bld.Damage(100000); return; }

if(IsAIPlayer(.player)){
	if (.hero.IsValid){ 
		h = .hero;
		.DetachFrom(h);
	}
}
ptStart = .posRH;
building = bld.AsBuilding;

.SetEntering(true);
pt = building.GetEnterPoint(this);
while (bld.IsValid)
	if (.GotoEnter(pt, 0, 1000, false, 0))
		break;

if (bld.IsValid){
	building.settlement.AddUnit(this);
} else {
	Sleep(rand(100)+30);
	//.AddCommand(false, "move", pt + Point(0, 1)); 
	.AddCommand(false, "move", ptStart);/// prevent moving all units on the same place
}
